package com.alpha.bom;

import java.util.ArrayList;

/**
 * This class represents a Question object
 * 
 * @author Mishael Mae C. Legaspi
 * @version 1.0
 * @since JDK1.7
 */
public class Question implements Comparable<Question>{
	private int questionId;
	private String questionType;
	private String question;
	private Answer correctAnswer;
	private String category;
	private ArrayList<Answer> choices;
	
	/**
	 * This is used to instantiate a question with the given question ID,
	 * question type, question text, question category, and the correct
	 * answer for this question.
	 * @param questionId The question ID
	 * @param questionType The question type (Multiple choice, True or False, etc.)
	 * @param question The question
	 * @param correctAnswer The correct answer for this question
	 * @param category The category of the question as specified by administrator
	 */
	public Question(int questionId, String questionType, String question, Answer correctAnswer, String category) {
		super();
		this.questionId = questionId;
		this.questionType = questionType;
		this.question = question;
		this.correctAnswer = correctAnswer;
		this.category = category;
		this.choices = new ArrayList<Answer>();
	}

	/**
	 * This is used to retrieve the question ID
	 * @return The question ID
	 */
	public int getQuestionId() {
		return questionId;
	}
	
	/**
	 * This is used to set the question ID
	 * @param questionId Question ID to set
	 */
	public void setQuestionId(int questionId) {
		this.questionId = questionId;
	}
	
	/**
	 * This is used to retrieve the type of the question
	 * @return The type of the question
	 */
	public String getQuestionType() {
		return questionType;
	}
	
	/**
	 * This is used to set the type of the question
	 * @param questionType Question type to set
	 */
	public void setQuestionType(String questionType) {
		this.questionType = questionType;
	}
	
	/**
	 * This is used to retrieve the question
	 * @return The question
	 */
	public String getQuestion() {
		return question;
	}
	
	/**
	 * This is used to set the question
	 * @param question Question to set
	 */
	public void setQuestion(String question) {
		this.question = question;
	}

	/**
	 * This is used to retrieve the correct answer for the question
	 * @return The correct answer for the question
	 */
	public Answer getCorrectAnswer() {
		return correctAnswer;
	}

	/**
	 * This is used to set the correct answer for the question
	 * @param correctAnswer The correct answer to set
	 */
	public void setCorrectAnswer(Answer correctAnswer) {
		this.correctAnswer = correctAnswer;
	}
	
	/**
	 * This is used to set the category of the question
	 * @param category the category to set
	 */
	public void setCategory(String category) {
		this.category = category;
	}

	/**
	 * This is used to retrieve the category of the question
	 * @return the category
	 */
	public String getCategory() {
		return category;
	}

	/**
	 * This is used to set the choices for the question
	 * @param choices the choices to set
	 */
	public void setChoices(ArrayList<Answer> choices) {
		this.choices = choices;
	}

	/**
	 * This is used to retrieve the choices for the question
	 * @return the choices
	 */
	public ArrayList<Answer> getChoices() {
		return choices;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + questionId;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Question other = (Question) obj;
		if (questionId != other.questionId)
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Question [questionId=" + questionId + ", questionType="
				+ questionType + ", question=" + question + "]";
	}

	@Override
	public int compareTo(Question arg0) {
		return this.questionId - arg0.getQuestionId();
	}
	
}
